var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        }),
    r = function (e, t, o, n) {
        var i,
            a = arguments.length,
            r = a < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, o)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(e, t, o, n);
        else
            for (var s = e.length - 1; s >= 0; s--)
                (i = e[s]) && (r = (a < 3 ? i(r) : a > 3 ? i(t, o, r) : i(t, o)) || r);
        return a > 3 && r && Object.defineProperty(t, o, r), r;
    };
Object.defineProperty(i, "__esModule", {value: !0});
var s = e("AssetsMap"),
    c = e("BundleNames"),
    l = e("Util"),
    d = e("ConfigGameData"),
    u = cc._decorator,
    p = u.ccclass,
    h =
        (u.property,
        (function (e) {
            function t() {
                var t = (null !== e && e.apply(this, arguments)) || this;
                return (
                    (t.headNode = null),
                    (t.tailNode = null),
                    (t.bodyNodeList = null),
                    (t.skinData = null),
                    (t.circleCenter = cc.v2(0, 0)),
                    (t.circleRadius = 0),
                    (t.carSpeed = 0),
                    (t.radian = 0),
                    (t.angle = 0),
                    (t.isTop = !0),
                    (t.dance_dt = 5),
                    (t.bodys_pos = []),
                    (t._old_pos_x = null),
                    (t._old_pos_y = null),
                    t
                );
            }
            return (
                a(t, e),
                (t.prototype.init = function (e, t) {
                    void 0 === e && (e = 0.8),
                        void 0 === t && (t = 5),
                        (this.dance_dt = t),
                        (this.node.scale = 0.8),
                        (this.bodyNodeList = []),
                        this.headNode ||
                            (this.headNode = game.UIManager.instance.createNodeByPreloading(
                                c.default.Game,
                                s.default.GameBundle.prefabs.assetsList.headPrefab
                            )),
                        this.tailNode ||
                            (this.tailNode = game.UIManager.instance.createNodeByPreloading(
                                c.default.Game,
                                s.default.GameBundle.prefabs.assetsList.tailPrefab
                            ));
                    for (var o = 0; o < 12; o++) {
                        var n = game.UIManager.instance.createNodeByPreloading(
                            c.default.Game,
                            s.default.GameBundle.prefabs.assetsList.bodyPrefab
                        );
                        (n.parent = this.node), (n.zIndex = -o), (n.scale = e), (n.x = 1e4), this.bodyNodeList.push(n);
                    }
                    (this.headNode.parent = this.node),
                        (this.headNode.zIndex = 100),
                        (this.headNode.scale = e),
                        (this.headNode.x = 1e4),
                        (this.tailNode.parent = this.node),
                        (this.tailNode.scale = e),
                        (this.tailNode.zIndex = -100),
                        (this.tailNode.x = 1e4),
                        this.__onLoad();
                }),
                (t.prototype.refreshView = function (e, t) {
                    void 0 === t && (t = 0), (this.skinData = e);
                    for (
                        var o = e.initlength[e.level],
                            n = 0,
                            i = [
                                30, 30, 30, 30, 30, 40, 50, 60, 80, 100, 120, 150, 180, 210, 240, 280, 320, 360, 410,
                                460, 510, 570, 630, 690, 750
                            ],
                            a = 0;
                        a < i.length;
                        a++
                    )
                        i[a] == o && (n = a);
                    0 != t && (n = t);
                    var r = game.BundleManager.instance
                        .getBundle(c.default.Game)
                        .get(s.default.GameBundle.textures.assetsList[e.name + "_head_0"], cc.SpriteFrame);
                    this.headNode.getChildByName("image").getChildByName("sprite").getComponent(cc.Sprite).spriteFrame =
                        r;
                    var l = this.tailNode.getChildByName("sprite"),
                        d = game.BundleManager.instance
                            .getBundle(c.default.Game)
                            .get(s.default.GameBundle.textures.assetsList[e.name + "_tail"], cc.SpriteFrame);
                    for (l.getComponent(cc.Sprite).spriteFrame = d, a = 0; a < this.bodyNodeList.length; a++) {
                        var u = this.bodyNodeList[a];
                        u.active = a <= n + 1;
                        var p = a % 2 == 0 ? 1 : 2,
                            h = e.name + "_body_" + p,
                            f = game.BundleManager.instance
                                .getBundle(c.default.Game)
                                .get(s.default.GameBundle.textures.assetsList[h], cc.SpriteFrame);
                        u.getComponent(cc.Sprite).spriteFrame = f;
                    }
                }),
                (t.prototype.__onLoad = function () {
                    this.schedule(this.circleMove, 0.01),
                        (this.carSpeed = 200),
                        (this.carSpeed = 0.01 * this.carSpeed),
                        (this.circleRadius = 100),
                        (this.isTop = 0 == l.default.randomFrom(0, 1)),
                        this.isTop
                            ? (this.angle = l.default.randomFrom(0, 360))
                            : (this.angle = l.default.randomFrom(-360, 0));
                    for (var e = 0; e < 50; e++) this.circleMove(0.01);
                }),
                (t.prototype.circleMove = function () {
                    if (this.isTop) {
                        (this.circleCenter.x = 0),
                            (this.circleCenter.y = 100),
                            (this.angle = this.angle + this.carSpeed),
                            (this.radian = (this.angle * Math.PI) / 180);
                        var e = this.circleRadius * Math.cos(this.radian) + this.circleCenter.x,
                            t = this.circleRadius * Math.sin(this.radian) + this.circleCenter.y,
                            o = cc.v3(e, t, 0);
                        Math.abs(this.angle - 270) >= 360 && ((this.isTop = !this.isTop), (this.angle = 90)),
                            this.playAct(o);
                    } else
                        (this.circleCenter.x = 0),
                            (this.circleCenter.y = -100),
                            (this.angle = this.angle - this.carSpeed),
                            (this.radian = (this.angle * Math.PI) / 180),
                            (e = this.circleRadius * Math.cos(this.radian) + this.circleCenter.x),
                            (t = this.circleRadius * Math.sin(this.radian) + this.circleCenter.y),
                            (o = cc.v3(e, t, 0)),
                            this.playAct(o),
                            Math.abs(this.angle - 90) >= 360 && ((this.isTop = !this.isTop), (this.angle = 270));
                }),
                (t.prototype.playAct = function (e) {
                    if (null == this._old_pos_x || null == this._old_pos_y)
                        return (this._old_pos_x = e.x), (this._old_pos_y = e.y), void (this.headNode.position = e);
                    this.headNode.position = e;
                    var t = cc.v2(this.headNode.x - this._old_pos_x, this.headNode.y - this._old_pos_y);
                    t = t.normalize();
                    var o = d.default.vectorToAngle(t.normalize());
                    (this.headNode.angle = o - 90),
                        (this._old_pos_x = e.x),
                        (this._old_pos_y = e.y),
                        this.bodys_pos.unshift(e),
                        this.bodys_pos.length > this.bodyNodeList.length * this.dance_dt && this.bodys_pos.pop();
                    for (var n = 0, i = 0; i < this.bodyNodeList.length; i++) {
                        var a = this.bodyNodeList[i],
                            r = i * this.dance_dt;
                        if (r >= this.bodys_pos.length) break;
                        (a.position = this.bodys_pos[r]), a.active && (n = i);
                    }
                    if (n > 0) {
                        var s, c;
                        (s = this.bodyNodeList[n]), (c = this.bodyNodeList[n - 1]);
                        var l = cc.v2(s.x - c.x, s.y - c.y);
                        l = l.normalize();
                        var u = d.default.vectorToAngle(l.normalize());
                        (this.tailNode.angle = u - 90), (this.tailNode.position = this.bodyNodeList[n].position);
                    }
                }),
                (t.prototype.refreshDressUp = function () {
                    var e = Number(l.default.getItem("dressItemUse" + this.skinData.index, "-1")),
                        t = this.headNode
                            .getChildByName("image")
                            .getChildByName("decorate_icon")
                            .getComponent(cc.Sprite);
                    if (e < 0) t.spriteFrame = null;
                    else {
                        var o = game.BundleManager.instance
                            .getBundle(c.default.Game)
                            .get(s.default.GameBundle.textures.assetsList["decorate_icon_" + e], cc.SpriteFrame);
                        t.spriteFrame = o;
                    }
                }),
                (t.prototype.stop = function () {
                    this.unschedule(this.circleMove);
                }),
                r([p], t)
            );
        })(cc.Component));
i.default = h;
